package com.itheima.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.pojo.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/session")
public class TestSessionController {

    @RequestMapping("get")
    public Result getSession(HttpSession session) {
        JSONObject obj = new JSONObject();
        obj.put("username", session.getAttribute("username"));
        obj.put("password", session.getAttribute("password"));
        return Result.success(obj);
    }

    @RequestMapping("save")
    public Result saveSession(HttpSession session) {
        session.setAttribute("username", "孙铭");
        session.setAttribute("password", "123456");
        return Result.success();
    }

}
